import store from '@/store/Store'
import { auth } from '../axios/userRequest'

const routes = [
  {
    path:'/',
    redirect:'/login',
  },{
    path:'/login',
    beforeEnter:(to,from)=>{
      if(localStorage.userCenter_token) return '/user-center'
    },
    component: () => import ('@/views/login')
  },
  {
  path: '/user-center',
  component: () => import ('@/views/users/userCenter'),
  beforeEnter: async (to, from) => {
    const res = await auth()
    if(res.code !== 0){
      localStorage.removeItem('userCenter_token')
      return '/login'
    }
    store.commit('userStore/changeStoreState',['isLogin',true])
  },
  redirect: '/user-center/user-index',
  children: [
    {
      path: 'user-index',
      name: 'userIndex.index',
      component: () => import('@/views/users/userIndex')
    }, {
      path: 'short-link-manage',
      name: 'shortLink.manage',
      component: () => import('@/views/users/userShortLink/shortGroup'),
      redirect: '/user-center/short-link-manage/0',
      children: [{
        path: ':id',
        name: 'shortLink.link',
        component: () => import('@/views/users/userShortLink/shortLink'),
        children: [{
          path: 'plugin',
          name: 'shortLink.plugin',
          component: () => import('@/views/users/userShortLink/shortPlugin')
        }]
      }]
    }, {
      path: 'short-domain',
      name: 'shortLink.domain',
      component: () => import('@/views/users/userShortLink/shortDomain')
    },  {
      path: 'live-code',
      name: 'liveCode.center',
      component: () => import('@/views/users/userLiveCode/liveCodeCenter'),
      redirect: '/user-center/live-code/manage',
      children: [{
        path: 'manage',
        name: 'liveCode.manage',
        component: () => import('@/views/users/userLiveCode/liveCodeManage'),
      },{
        path: 'create',
        name: 'liveCode.create',
        component: () => import('@/views/users/userLiveCode/createLiveCode')
      },{
        path: 'group/:id',
        name: 'liveCode.groupQrcode',
        component: () => import('@/views/users/userLiveCode/groupQRcode')
      },{
        path: 'ordinary/:id',
        name: 'liveCode.ordinaryQrcode',
        component: () => import('@/views/users/userLiveCode/ordinaryQRcode')
      }]
    }, {
      path: 'old-code',
      name:'userOldCodeCenter',
      component:()=>import('@/views/users/userOldCode/oldCodeCenter'),
      redirect: '/user-center/old-code/0',
      children: [{
        path: ':id',
        name:'synchysisCode.oldCode',
        component:()=>import('@/views/users/userOldCode/synchysisCode'),
      }]
    },
    {
      path: 'old-code-domain',
      name:'synchysisCode.oldCodeDomain',
      component:()=>import('@/views/users/userOldCode/oldCodeDomain'),
    },
    {
      path: 'live-code-domain',
      name: 'liveCode.domain',
      component: () => import('@/views/users/userLiveCode/liveCodeDomain')
    }, {
      path: 'short-statistics',
      name: 'shortLink.statistics',
      component: () => import('@/views/users/userShortLink/shortStatistics')
    }, {
      path: 'live-code-statistics',
      name: 'liveCode.statistics',
      component: () => import('@/views/users/userLiveCode/liveCodeStatistics')
    }, {
      path: 'domain-detection',
      name: 'remind.detection',
      component: () => import('@/views/users/userRemind/domainDetection'),
      children: [{
        path: 'batch',
        name: 'remind.batch',
        component: () => import('@/views/users/userRemind/batchDetection')
      }]
    },{
      path: 'monitor-system',
      name: 'remind.monitor',
      component: () => import('@/views/users/userRemind/monitorSystem')
    },
    //回收站
    {
      path: 'recyle-bin-short',
      name: 'recyleBin.center',
      component: () => import('@/views/users/userRecycleBin/recycleBinCenter'),
      redirect: '/user-center/recyle-bin-short/0',
      children: [{
        path: ':id',
        name: 'recyleBin.shortLink',
        component: () => import('@/views/users/userRecycleBin/recycleBinShortLink')
      }]
    },
    {
      path: 'recyle-bin-live-code',
      name: 'recyleBin.liveCode',
      component: () => import('@/views/users/userRecycleBin/recycleBinLiveCode'),
    },
    {
      path: 'user-notice',
      name: 'userNotice.notice',
      component: () => import('@/views/users/userNotice/userNotice'),
      children: [
        {
          path: ':id',
          component: () => import('@/views/users/userNotice/noticeDetails'),
          props: { default: true }
        }
      ]
    }, {
      path: 'user-account',
      component: () => import('@/views/users/userAccount/userAccount'),
      children: [{
        path: 'user-setting',
        component: () => import('@/views/users/userAccount/userSetting')
      }]
    }, {
      path: 'logout',
      redirect: to => {
        store.commit('userStore/logout')
      }
    }]
}]

export default routes
